<template>
  <div>
    <el-row>
      <el-col :span="24" align="right">
        <div style="margin-top:10px">
          <el-input style="width:200px" v-model="filters.eventName" placeholder="事件名称"></el-input>
          <el-select style="width:200px" v-model="filters.eventTypeValue" placeholder="事件类型">
            <el-option v-for="(v,i) of EventType" :key="i" :label="v.eventTypeName" :value="v.eventTypeValue"></el-option>
          </el-select>
          <el-button type="primary" icon="search" @click="getInfo">搜索</el-button>
          <el-button type="primary" @click="flushAll">刷新</el-button>
        </div>
        <el-row style="margin-top:20px">
          <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
            <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
          </el-col>
          <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
            <el-table :data="list" border>
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column prop="eventName" label="事件名称" align="center"></el-table-column>
              <el-table-column prop="eventPlace" label="发生地点" align="center"></el-table-column>
              <el-table-column prop="evenScaleTypeName" label="事件规模" align="center"></el-table-column>
              <el-table-column prop="eventTypeName" label="事件类型" align="center"></el-table-column>
              <el-table-column prop="eventDate" label="发生时间" align="center"></el-table-column>
              <el-table-column prop="eventStatusName" label="事件处理状态" align="center"></el-table-column>
              <el-table-column label="操作" width="200" align="center">
                <template scope="scope">
                  <el-button size="small" v-if="scope.row.eventStatus=='05'||scope.row.eventStatus=='08'" type="success" @click="eventDeal(scope.row.disputeEventID)">事件处理</el-button>
                  <el-button type="text" @click="ckDetail(scope.row.disputeEventID)">查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
             <el-pagination style="margin-top:10px;float:right" layout="prev, pager, next" :total="totalInfo"  @current-change="handleCurrentChange">
            </el-pagination>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
    <el-dialog title="事件处理" :visible.sync="visible" :before-close="handleClose">
      <el-form :model="form" label-width="180px">
        <el-form-item label="事件处理人ID" style="width:600px">
          <el-input disabled v-model="form.dealingUserID" placeholder=""></el-input>
        </el-form-item>
        <el-form-item label="处理时间">
          <el-date-picker v-model="form.dealingTime" placeholder=""></el-date-picker>
        </el-form-item>
        <el-form-item label="处理情况">
          <el-input style="width:500px" v-model="form.dealingInf" type="textarea" placeholder=""></el-input>
        </el-form-item>
        <el-form-item label="请选择化解方式">
          <el-select v-model="form.solvingMethodType" placeholder="">
            <el-option v-for="(v,i) of SolvingMethodType" :key="i" :label="v.solvingMethodTypeName" :value="v.solvingMethodTypeValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否调解成功">
          <el-radio-group v-model="form.isSuccessInSolving">
            <el-radio :label="1">成功</el-radio>
            <el-radio :label="0">失败</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" style="width:600px">
          <el-input v-model="form.remark" placeholder=""></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="deal()">确认处理</el-button>
        </el-form-item>
        <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
          <h1>图片、视频信息</h1>
        </el-form-item>
        <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
          <el-upload class="upload-demo"
            :action="getDomain()+'/msmis/api/dispute/addDisputeEventDealingPictures?ID='+form.eventDealingID"
            :headers="header"
            :file-list="fileList" list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">可上传jpg/jpeg/png文件</div>
          </el-upload>
        </el-form-item>
        <el-form-item v-if="form.eventDealingID!==''&&form.eventDealingID!==null">
          <h4>视频上传</h4>
          <el-upload class="upload-demo" drag
            :action="getDomain()+'/msmis/api/dispute/addDisputeEventDealingVideo?ID='+form.eventDealingID"
            :headers="header"
            multiple>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将视频拖到此处，或
              <em>点击上传</em>
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="visible=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog top="5%" title="查看详情" :visible.sync="visible2">
      <info :id="id"></info>
    </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "@/api/contradictionManage/index";
import * as api3 from "../../api/securityManage";
import * as api2 from "@/api/zonghezhili/duiwujianshe";
import { getToken } from "../../utils/auth";
import * as socket from "@/api";
import info from "./checkDetail";
export default {
  components: {
    treeComponent: treeComponent,
    info:info
  },
  data() {
    return {
      header: {
        token: getToken()
      },
      EventType: [],
      visible: false,
      visible2: false,
      id:"",
      filters: {
        id: 4,
        eventName: null, // 事件名称
        majorPersonName: null, // 主要当事人
        eventTypeValue: null,
        netGridID: null,
        page: 1,
        pageSize: 10
      },
      fileList: [],
      currentID: "",
      AccidentType: [],
      AccidentKind: [],
      EventStatus: [],
      form: {
        eventDealingID: "",
        eventID: "",
        dealingUserID: 4, // bigint comment '处理任务的人的用户ID',
        dealingTime: "", //   datetime,
        solvingMethodType: "", // char(4) DEFAULT NULL,
        isSuccessInSolving: "", // int(11) DEFAULT NULL,
        dealingInf: "", //  varchar(1000) comment '处理情况文字描述',
        remark: "" //  varchar(500),
      },
      list: [
        {
          disputeEventID: "", //       bigint not null auto_increment,
          eventName: "", //             '事件名称',
          eventDate: "", //             '事件发生日期',
          eventPlace: "", //            '事件发生地点',
          evenScaleTypeValue: "", //    '事件规模',
          eventTypeValue: "", //        '事件类型编码',
          numberofJoinning: "", //      '涉及人数',
          eventIntroduction: "", //     '事件简述，不超2000字',
          relatedOrg: "", //            '涉及单位',
          majorPersonCertTypeCode: "", //'主要当事人证件代码类型，编码规范GA/T 517',
          majorPersonCertID: "", //     '主要当事人证件号码',
          majorPersonName: "", //       char(80),
          majorPersonSex: "", //        '主要当事人性别，编码符合GB/T 2261.1',
          majorPersonEthnicity: "", //  '主要当事人名族类别，详细见字典表',
          majorPersonEducation: "", //  '主要当事人学历类别，编码见表',
          majorPersonType: "", //       '主要当事人人员类别',
          majorPersonDetailAddress: "", //  '主要当事人居住详细地址',
          solvingDeadline: "", //      '化解时限',
          solvingMethodType: "", //    '化解方式，编码见 GBT 31000-2015文件之5.58',
          solvingManagment: "", //     '化解组织',
          solvingByPersonName: "", //   '化解责任人姓名',
          solvingByPersonContact: "", //'化解责任人联系方式，手机号或固定电话',
          isSuccessInSolving: "", //   '化解是否成功？值1表示成功，0表示不成功。',
          solvingIntroduction: "", //  '化解情况，不超2000字',
          evaluationDate: "", //       '考评日期，格式为YYYYMMDD',
          evaluationSuggestion: "", // '考评意见，不超2000字。',
          longitude: "", //            '地理经度信息，数字32，8',
          latitude: "", //             '地理纬度信息',
          eventStatus: "", //          '事件处理状态编码类型，见编码状态类型表',
          eventCheckStatus: "",
          netGridID: 1
        }
      ],
      totalInfo: 0,
      SolvingMethodType: []
    };
  },
  methods: {
    getDomain() {
      return "http://" + window.location.host;
    },
    handleClose(done) {
      this.form.eventDealingID = "";
      done();
    },
    deal() {
      this.form.eventID = this.currentID;
      this.$confirm("是上传此事件的处理记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api.addDisputeEventDealing(this.form).then(res => {
            if (res.code == 200) {
              this.form.eventDealingID = res.data;
              this.$message({
                type: "success",
                message: "事件处理信息上传成功！"
              });
              api.updateDisputeEventStatus("06", this.form.eventID).then(res => {
                  if (res.code == 200) {
                    this.$message({
                      type: "success",
                      message: "等待审核！"
                    });
                    let that = this;
                    socket.send({username:4,message:'有新的矛盾纠纷事件需要审核!'});
                    this.getInfo();
                  }
                });
            } else {
              this.$message({
                type: "error",
                message: "事件处理信息上传失败！"
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消上传事件处理信息！"
          });
        });
    },
    eventDeal(id) {
      this.currentID = id;
      this.visible = true;
    },
    flushAll() {
      this.filters.eventName = this.filters.eventTypeValue = null;
      if (this.$store.getters.user.userRole == "超级管理员") {
        this.filters.netGridID = null;
      }
      this.getInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getInfo();
    },
    ckDetail(id) {
      this.id = id;
      this.visible2 = true;
    },
    addNewRecord() {
      this.$router.push("add");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getInfo();
    },
    editEvent(id) {
      this.$router.push({
        path: "editDeal",
        query: {
          id: id
        }
      });
    },
    getInfo() {
      api.getDisputeEventHandlerQuery(this.filters).then(res => {
        this.list = res.data.disputeEvents;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filters.eventName = this.filters.eventTypeValue = null;
    }
  },
  mounted() {
    this.form.dealingUserID = this.$store.getters.user.userID;
    this.filters.id = this.$store.getters.user.userID;
    if (this.$store.getters.user.userRole != "超级管理员")
      this.filters.netGridID = this.$store.getters.user.netGridID;
    this.getInfo();
    api2.fetchServedPersonManageTypes().then(res => {
      this.EventType = res.data.codeEventType;
      this.SolvingMethodType = res.data.codeSolvingMethodType;
    });
    api3.getSSEventCode().then(res => {
      this.EventStatus = res.data.EventStatusType;
    });
  }
};
</script>


<style scoped>

</style>
